import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'dashboard',
    hidden: true,
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
      }
    ]
  },
  /* 经典案例模块 */
  {
    path: '/example',
    component: Layout,
    redirect: '/example/index',
    name: '案例',
    meta: { title: '案例', icon: 'example' },
    children: [
      {
        path: 'index',
        name: '表格',
        component: () => import('@/views/example/index'),
        meta: { title: '普通表格' }
      },
      {
        path: 'tableInlineEdit',
        name: '表格内部编辑',
        component: () => import('@/views/example/tableInlineEdit'),
        meta: { title: '表格内部编辑' }
      },
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/example/tree/index'),
        meta: { title: '树形表格' }
      },
      {
        path: 'treeSelect',
        name: 'treeSelect',
        component: () => import('@/views/example/treeSelect'),
        meta: { title: '树形下拉框' }
      },
      {
        path: 'MDinput',
        name: 'MDinput',
        component: () => import('@/views/example/MDinput'),
        meta: { title: 'MDinput' }
      },
      {
        path: 'BackToTop',
        name: 'BackToTop',
        component: () => import('@/views/example/BackToTop'),
        meta: { title: '返回顶部' }
      },
      {
        path: 'TableDrag',
        name: 'TableDrag',
        component: () => import('@/views/example/TableDrag'),
        meta: { title: '表格拖拽' }
      },
      {
        path: 'Transition',
        name: 'Transition',
        component: () => import('@/views/example/Transition'),
        meta: { title: 'vue动画' }
      }
    ]
  },

  /* Echars图 */
  {
    path: '/Echars',
    component: Layout,
    redirect: '/Echars/line',
    name: '图表',
    meta: { title: '图表', icon: 'zonghe' },
    children: [
      {
        path: 'line',
        name: 'echars',
        component: () => import('@/views/Echars/line'),
        meta: { title: '折线图表' }
      },
      {
        path: 'keyboard',
        name: 'keyboard',
        component: () => import('@/views/Echars/keyboard'),
        meta: { title: '键盘图表' }
      },
      {
        path: 'mixChart',
        name: 'mixChart',
        component: () => import('@/views/Echars/mixChart'),
        meta: { title: '混合图表' }
      }
    ]
  },

  {
    path: '/Vue',
    component: Layout,
    redirect: '/Vue/test',
    name: 'vue官网案例',
    meta: { title: 'vue官网案例', icon: 'table' },
    children: [
      {
        path: 'test',
        name: 'vue案例',
        component: () => import('@/views/Vue/test'),
        meta: { title: 'vue官网' }
      },
      {
        path: 'conditional',
        name: 'conditional',
        component: () => import('@/views/Vue/conditional'),
        meta: { title: '条件渲染' }
      },
      {
        path: 'buyCar',
        name: 'buyCar',
        component: () => import('@/views/Vue/buyCar'),
        meta: { title: '购物车案例' }
      },
      {
        path: 'slot',
        name: 'slot',
        component: () => import('@/views/Vue/slotStudy/slot'),
        meta: { title: 'slot卡槽' }
      },
      {
        path: 'componentUse',
        name: 'componentUse',
        component: () => import('@/views/Vue/ComponentStudy/componentUse'),
        meta: { title: '组件的高级使用' }
      }
    ]
  },

  {
    path: '/demo',
    component: Layout,
    redirect: '/demo/numberInput',
    name: 'demo开发',
    meta: { title: 'demo开发', icon: 'demo' },
    children: [
      {
        path: 'numberInput',
        name: 'numberInput',
        component: () => import('@/views/demo/numberInput/numberInput'),
        meta: { title: '数字输入框' }
      },
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/demo/tabPage/index'),
        meta: { title: 'tab标签页' }
      }
    ]
  },

  {
    path: '/customDirective',
    component: Layout,
    redirect: '/customDirective/focus',
    name: '自定义指令',
    meta: { title: '自定义指令', icon: 'directive' },
    children: [
      {
        path: 'focus',
        name: 'focus',
        component: () => import('@/views/customDirective/focus'),
        meta: { title: '自动获取焦点' }
      },
      {
        path: 'timeStamp',
        name: 'timeStamp',
        component: () => import('@/views/customDirective/timeStamp'),
        meta: { title: '时间转换指令' }
      }
    ]
  },

  {
    path: '/vueBusDemo',
    component: Layout,
    redirect: '/vueBusDemo/index',
    children: [
      {
        path: 'index',
        name: 'vueBus',
        component: () => import('@/views/vueBusDemo/index'),
        meta: { title: '中央事件总线子页面', icon: 'bus' }
      }
    ]
  },

  /* 电商网站开发 */
  {
    path: '/onlineWebsite',
    component: Layout,
    redirect: '/onlineWebsite/index',
    children: [
      {
        path: 'index',
        name: '电商网站页面',
        component: () => import('@/views/onlineWebsite/index'),
        meta: { title: '电商网站', icon: 'daily' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
